import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

const state = {
	editableTabs: [{
          title: 'Tab 1',
          name: '1',
          content: 'Tab 1 content'
    }],
	count: 1,
	editableTabsValue: '1',

}

const mutations = {
	// 打开新的tab页面
	openTab(state,url){
		let newTabName = ++state.count + '';
		state.editableTabs.push({
			title: 'new tab',
			name: newTabName,
			content: url
		})
		state.editableTabsValue = newTabName;
		state.count = state.count + 1;
	},
	setEditableTabs(state, value){
		state.editableTabs = value;
	},
	setEditableTabsValue(state,value) {
		state.editableTabsValue = value
	}
}


const actions = {
	// 打开新的tab页面
	openTab: ({commit},url) => commit('openTab',url),
	setEditableTabs: ({commit,state},editableTabs) => commit('setEditableTabs',editableTabs),
	setEditableTabsValue: ({commit,state},editableTabsValue) => commit('setEditableTabsValue',editableTabsValue)
}

const getters = {
	editableTabsValue: state => state.editableTabsValue,
	editableTabs: state => state.editableTabs
}

const store = new Vuex.Store({
	state,
	mutations,
	actions,
	getters
})

export default store;